/**
 * @param {number} n
 * @return {number}
 */
var totalNQueens = function (n) {
    let res = 0
    let path = []
    const dfs = function (level) {
        if (path.length === n) {
            res++
            return
        }
        for (let i = 0; i < n; i++) {
            if (isValid(path, [level, i])) {
                path.push([level, i])
                dfs(level + 1)
                path.pop()
            }
        }
    }
    dfs(0)
    return res
};
function isValid(path, points) {
    for (let i = 0; i < path.length; i++) {
        if ((path[i][0] == points[0]) || (path[i][1] == points[1]) || (Math.abs(path[i][0] - points[0]) == Math.abs(path[i][1] - points[1]))) return false
    }
    return true
}
totalNQueens(4)